package cool.doudou.doudada.iot.codec.core.logger;

import lombok.extern.slf4j.Slf4j;
import org.apache.felix.framework.Logger;
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceReference;

/**
 * FelixLogger
 *
 * @author jiangcs
 * @since 2022/09/29
 */
@Slf4j
public class FelixLogger extends Logger {
    @Override
    protected void doLog(Bundle bundle, ServiceReference sr, int level, String msg, Throwable throwable) {
        switch (level) {
            case LOG_DEBUG:
                log.debug("symbolicName[{}] => {}", bundle.getSymbolicName(), msg, throwable);
                break;
            case LOG_INFO:
                log.info("symbolicName[{}] => {}", bundle.getSymbolicName(), msg, throwable);
                break;
            case LOG_WARNING:
                log.warn("symbolicName[{}] => {}", bundle.getSymbolicName(), msg, throwable);
                break;
            case LOG_ERROR:
                log.error("symbolicName[{}] => {}", bundle.getSymbolicName(), msg, throwable);
                break;
            default:
                log.trace("symbolicName[{}] => {}", bundle.getSymbolicName(), msg, throwable);
        }
    }

    @Override
    protected void doLog(int level, String msg, Throwable throwable) {
        switch (level) {
            case LOG_DEBUG:
                log.debug(msg, throwable);
                break;
            case LOG_INFO:
                log.info(msg, throwable);
                break;
            case LOG_WARNING:
                log.warn(msg, throwable);
                break;
            case LOG_ERROR:
                log.error(msg, throwable);
                break;
            default:
                log.trace(msg, throwable);
        }
    }
}
